package erwiki.ui.app;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.rap.e4.E4ApplicationConfig;
import org.eclipse.rap.e4.E4EntryPointFactory;
import org.eclipse.rap.rwt.application.Application;
import org.eclipse.rap.rwt.application.Application.OperationMode;
import org.eclipse.rap.rwt.application.ApplicationConfiguration;
import org.eclipse.rap.rwt.client.WebClient;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

import erwiki.api.core.Engine;

//@formatter:off
@Component(
	name = "e4applicationConfig",
	service = { ApplicationConfiguration.class })
//@formatter:on
public class ApplicationConfig implements ApplicationConfiguration {

	private final static String E4XMI = "platform:/plugin/erwiki.ui/Application.e4xmi";
	private final static String LIFECYCLE = "bundleclass://erwiki.ui/erwiki.ui.app.lifecycle.ApplicationLifecycle";

	@Reference
	Engine engine;

	public void configure(Application application) {
		Map<String, String> properties = new HashMap<String, String>();
		properties.put(WebClient.PAGE_TITLE, "ErWiki e4");

		E4ApplicationConfig config = E4ApplicationConfig.create(E4XMI, LIFECYCLE);
		//:FVK:E4ApplicationConfig config = E4ApplicationConfig.create(E4XMI);
		E4EntryPointFactory entryPointFactory = new E4EntryPointFactory(config);
		application.addEntryPoint("/", entryPointFactory, properties);
		application.setOperationMode(OperationMode.SWT_COMPATIBILITY);
		
		//TODO:
		/*
		ClientResources clientResources = new ClientResources(application);
		clientResources.registerResources();
		 */
	}

}
